﻿using MediatR;
using RedDragon.Common.Domain.produceplan;
using RedDragon.Common.Infrastructure.Interface;
using T.Common.Domain.Common;

namespace RedDragon.RBAC.API.Application.Common.produceplanW
{
    public class produceplanUpdateHandler : IRequestHandler<produceplanUpdateCommon, Result>
    {
        public readonly IBaseRepository<produceplan> produceplanRepository;

        public produceplanUpdateHandler(IBaseRepository<produceplan> produceplanRepository)
        {
            this.produceplanRepository = produceplanRepository;
        }

        public async Task<Result> Handle(produceplanUpdateCommon request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = 0, Msg = "主生产计划修改失败" };
            try
            {
                var list = produceplanRepository.Query().Where(x => x.produceplanId == request.ProduceplanId).ToList();
                foreach (var item in list)
                {
                    item.produceplanNumber = request.produceplanNumber;
                    item.produceplanName = request.produceplanName;
                    item.produceplanDetail = request.produceplanDetail;
                    item.produceplanStatus = request.produceplanStatus;
                    item.MakeName = request.MakeName;
                    item.MakeDepartment = request.MakeDepartment;
                    item.CreateTime = DateTime.Now;
                    item.produceplanAudit = 0;
                    produceplanRepository.Update(item);
                }
                if (list != null)
                {
                    result.Code = 1;
                    result.Msg = "主生产计划修改成功";
                }



            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
